home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / math / ast51src.zip / PLACALC.H < prev    next >
C/C++ Source or Header  |  1995-12-31  |  16KB  |  444 lines

  1. /*
  2. ** Astrolog (Version 5.10) File: placalc.h
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1995 by Walter D. Pullen
  6. ** (Astara@msn.com). Permission is granted to freely use and
  7. ** distribute these routines provided one doesn't sell, restrict, or
  8. ** profit from them in any way. Modification is allowed provided these
  9. ** notices remain with any altered or edited versions of the program.
  10. **
  11. ** The main planetary calculation routines used in this program have
  12. ** been Copyrighted and the core of this program is basically a
  13. ** conversion to C of the routines created by James Neely as listed in
  14. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  15. ** available from Matrix Software. The copyright gives us permission to
  16. ** use the routines for personal use but not to sell them or profit from
  17. ** them in any way.
  18. **
  19. ** The PostScript code within the core graphics routines are programmed
  20. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  21. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  22. **
  23. ** The extended accurate ephemeris databases and formulas are from the
  24. ** calculation routines in the program "Placalc" and are programmed and
  25. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  26. ** (alois@azur.ch). The use of that source code is subject to
  27. ** regulations made by Astrodienst Zurich, and the code is not in the
  28. ** public domain. This copyright notice must not be changed or removed
  29. ** by any user of this program.
  30. **
  31. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  32. ** X Window graphics initially programmed 10/23-29/1991.
  33. ** PostScript graphics initially programmed 11/29-30/1992.
  34. ** Last code change made 12/27/1995.
  35. */
  36.  
  37. #include "astrolog.h"
  38.  
  39.  
  40. #define EPHE_PATH EPHE_DIR
  41. #define HUGE8 1.7E+308     /* biggest value for REAL8 */
  42.  
  43. extern int lrz_file_posit();
  44. extern int ast_file_posit();
  45. extern int chi_file_posit();
  46. extern int outer_hel();
  47. extern void longreorder();
  48. extern int inpolq();
  49.  
  50. #ifdef PLACALC
  51. /************************************************************
  52. $Header: placalc.h,v 1.4 93/03/22 10:08:39 alois Exp $
  53. definitions and constants for planetary routines
  54.  
  55. ATTENTION: PLACALC USERS ON MSDOS:
  56. See the note close to the end of this file regarding EPHE_PATH.
  57.  
  58. ---------------------------------------------------------------
  59. | Copyright Astrodienst AG and Alois Treindl, 1991, 1993.     |
  60. | The use of this source code is subject to regulations made  |
  61. | by Astrodienst Zurich. The code is NOT in the public domain.|
  62. |                                                             |
  63. | This copyright notice must not be changed or removed        |
  64. | by any user of this program.                                |
  65. ---------------------------------------------------------------
  66. ************************************************************/
  67.  
  68. /************************************************************
  69. $Header: ourdef.h,v 1.2 91/11/16 16:21:37 alois Exp $
  70. definitions and constants for all Astrodienst C programs
  71. contains only declarations and #defines, no global variables.
  72. auto-dectection of MSDOS (TURBO_C or MS_C) or HPUNIX
  73. ************************************************************/
  74.  
  75. #ifdef MSDOS  /* already defined by some DOS compilers */
  76. #undef MSDOS
  77. #define MSDOS 1
  78. #endif
  79.  
  80. #ifdef __TURBOC__ /* defined by turboc */
  81. #ifndef MSDOS
  82. #define MSDOS 1
  83. #endif
  84. #define TURBO_C
  85. #endif
  86.  
  87. #if MSDOS
  88. #define HPUNIX 0
  89. #ifndef TURBO_C
  90. #define MS_C /* assume Microsoft C compiler */
  91. #endif
  92. #else
  93. #define MSDOS 0
  94. #define HPUNIX 1
  95. #ifndef _HPUX_SOURCE
  96. #define _HPUX_SOURCE
  97. #endif
  98. #endif
  99.  
  100. #include <stdlib.h>
  101. #if HPUNIX
  102. #ifndef MAC
  103. #ifndef NeXT
  104. #include <unistd.h>
  105. #endif
  106. #endif /* MAC */
  107. #endif /* HPUNIX */
  108.  
  109. #ifndef OK
  110. #define OK 0
  111. #define ERR (-1)
  112. #endif
  113.  
  114.  
  115. #define UCHP (unsigned char*)  /* used for casting *char  */
  116. #define UCP (unsigned char*)  /* used for casting *char  */
  117. #define SCP (char*)     /* used for casting *unsigned char */
  118. #define UCHAR unsigned char
  119.  
  120. #if HPUNIX
  121. #ifndef MAC
  122. #ifndef NeXT
  123. #include <malloc.h>
  124. #endif
  125. #endif /* MAC */
  126. typedef double  REAL8;  /* real with at least 64 bit precision */
  127. typedef float   REAL4;  /* real with at least 32 bit precision */
  128. typedef long    INT4;   /* signed integer with at least 32 bit precision */
  129. typedef unsigned long UINT4;
  130. /* unsigned integer with at least 32 bit precision */
  131. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  132. typedef int     INT1;   /* signed integer with at least 8  bit precision */
  133. #ifndef dbd_VERSION     /* db_vista defines boolean in vista.h already */
  134. typedef int     BOOLEAN;
  135. #endif
  136. typedef unsigned short UINT2; /* unsigned 16 bits */
  137. #define ABS4  abs   /* abs function for long */
  138. #endif /* HPUNIX */
  139.  
  140. #if MSDOS
  141. #ifdef TURBO_C
  142. #include <alloc.h>    /* MSC needs malloc ! */
  143. #else
  144. #include <malloc.h>
  145. #endif
  146. typedef double  REAL8;  /* real with at least 64 bit precision */
  147. typedef float   REAL4;  /* real with at least 32 bit precision */
  148. typedef long    INT4;   /* signed integer with at least 32 bit precision */
  149. typedef unsigned long UINT4;
  150.                         /* unsigned integer with at least 32 bit precision */
  151. typedef int     INT2;   /* signed integer with at least 16 bit precision */
  152. typedef int     INT1;   /* signed integer with at least 8  bit precision */
  153. typedef int     BOOLEAN;
  154. typedef unsigned int UINT2; /* unsigned 16 bits */
  155. #define ABS4  labs    /* abs function for long */
  156. #endif /* MSDOS */
  157.  
  158. #define COS8 RCos
  159. #define SIN8 RSin
  160. #define ASIN8 asin
  161. #define TAN8 RTan
  162. #define ATAN8 RAtn
  163. #define ATAN28 atan2
  164. #define EXP10(x) pow(10.0, (x))
  165. #define ABS8(x) RAbs(x)
  166.  
  167. #define TANERRLIMIT 1.0E-10     /* used to check for arguments close to pi */
  168. #define NEAR_ZERO   1.0E-16     /* used to compare for divisors close to 0 */
  169. #define BIGREAL     1.0E+38
  170.  
  171. #define DEGTORAD 0.0174532925199433
  172. #define RADTODEG 57.2957795130823
  173.  
  174. typedef INT4 centisec;   /* centiseconds used for angles and times */
  175. #define CS   (centisec)  /* use for casting */
  176. #define CSEC centisec    /* use for typing */
  177.  
  178. #define DEG     (360000L)   /* degree expressed in centiseconds */
  179. #define DEG7_30 (2700000L)  /* 7.5 degrees */
  180. #define DEG15   (15 * DEG)
  181. #define DEG24   (24 * DEG)
  182. #define DEG30   (30 * DEG)
  183. #define DEG60   (60 * DEG)
  184. #define DEG90   (90 * DEG)
  185. #define DEG120  (120 * DEG)
  186. #define DEG150  (150 * DEG)
  187. #define DEG180  (180 * DEG)
  188. #define DEG270  (270 * DEG)
  189. #define DEG360  (360 * DEG)
  190.  
  191. #define CSTORAD 4.84813681109536E-08 /* centisec to rad: pi / 180 /3600/100 */
  192. #define RADTOCS 2.06264806247096E+07 /* rad to centisec 180*3600*100/pi */
  193.  
  194. #define DEG2MSEC 3600000.0  /* degree to milliseconds */
  195. #define DEG2CSEC 360000.0   /* degree to centiseconds */
  196.  
  197. #define SEC2CSEC 100  /* seconds to centiseconds */
  198.  
  199. #define CS2DEG    (1.0/360000.0)  /* centisec to degree */
  200. #define CS2CIRCLE (CS2DEG/360.0)  /* centisec to circle */
  201. #define AU2INT    1e7             /* factor for long storage of A.U. */
  202.  
  203. #define CSMIN 6000L
  204. #define CSSEC 100L
  205.  
  206. #define SINDEG(x) sin(DEGTORAD * (x))
  207. #define COSDEG(x) cos(DEGTORAD * (x))
  208. #define TANDEG(x) tan(DEGTORAD * (x))
  209. #define SINCS(x)  sin((double)(CSTORAD * (x)))
  210. #define COSCS(x)  cos((double)(CSTORAD * (x)))
  211. #define TANCS(x)  tan((double)(CSTORAD * (x)))
  212.  
  213. /*************************************************************
  214. Exported functions:
  215.  
  216. In all functions the variable jd_ad indicates the use of
  217. Astrodienst relative julian days, and jd the use of absolute
  218. julian days.
  219. *************************************************************/
  220.  
  221. extern int nacalc();
  222. extern int calcserv();
  223. extern void helup();
  224. extern void togeo();
  225. extern int calc();
  226. extern int hel();
  227. extern int moon();
  228. extern REAL8 sidtime();
  229. extern REAL8 smod8360();
  230. extern REAL8 mod8360();
  231. extern REAL8 diff8360();
  232. extern REAL8 test_near_zero();
  233. extern REAL8 deltat();
  234. extern void to_mean_ekl();
  235. extern int afl2planet();
  236. extern void disturb();
  237. extern REAL8 fnu();
  238.  
  239. /*************************************************************
  240. definitions
  241. *************************************************************/
  242.  
  243. /*
  244. * planet index numbers, used to identify a planet in calc() and
  245. * other related functions.
  246. */
  247. #define SUN       0   /* used synonymously for earth too */
  248. #define EARTH     0
  249. #define MOON      1
  250. #define MERCURY   2
  251. #define VENUS     3
  252. #define MARS      4
  253. #define JUPITER   5
  254. #define SATURN    6
  255. #define URANUS    7
  256. #define NEPTUNE   8
  257. #define PLUTO     9
  258. #define MEAN_NODE 10
  259. #define TRUE_NODE 11
  260. #define CHIRON    12
  261. #define LILITH    13
  262. #define CERES     14
  263. #define PALLAS    15
  264. #define JUNO      16
  265. #define VESTA     17
  266.  
  267. /*************************************************************
  268. exported variables
  269. *************************************************************/
  270.  
  271. extern REAL8 meanekl;
  272. extern REAL8 ekl;
  273. extern REAL8 nut;
  274.  
  275. extern struct elements { /* actual elements at time thelup */
  276.   REAL8 tj,     /* centuries from epoch */
  277.   lg,     /* mean longitude in degrees of arc*/
  278.   pe,     /* longitude of the perihelion in degrees of arc*/
  279.   ex,     /* excentricity in degrees of arc*/
  280.   kn,     /* longitude of node in degrees of arc*/
  281.   in,     /* inclination of the orbit in degrees of arc*/
  282.   ma;     /* mean anomaly in degrees of arc*/
  283. } el [MARS + 1];
  284.  
  285. extern char *ephe_path;
  286.  
  287. /*
  288. * in a bitlist flag each planet is represented by a bit;
  289. * all 13 defined planets can be called at once with
  290. * LILITH is not automatically included
  291. */
  292. #define CALC_ALL_PLANET_BITS ((1 << 13) - 1) /* bits 0..12 set */
  293.  
  294. #define J2000 2451545.0 /* Epoch of JPL ephemeris DE200, absolute */
  295. #define J1950  2433282.423  /* Epoch of JPL ephemeris DE102 */
  296. #define JUL_OFFSET 2433282.0  /* offset of Astrodienst relative Julian date */
  297. #define EPOCH1850 -36524.0  /* jupiter,saturn 0 jan 1850, 12:00 */
  298. #define EPOCH1900 -18262.0  /* inner planets  0 jan 1900, 12:00 */
  299. #define EPOCH1950  0.0    /* pluto    0 jan 1950, 12:00 */
  300.                 /* this is the origin of the Astrodienst
  301.                    relative julian calendar system */
  302. #define EPOCH1960 3653.0 /* uranus,neptune 1 jan 1960, 12:00 */
  303.  
  304. #define ENDMARK 99 /* used to mark the end of disturbation terms */
  305.  
  306. #define NODE_INTERVAL 0.005        /* days, = 7m20s */
  307. #define MOON_SPEED_INTERVAL 0.0001 /* 8.64 seconds later */
  308.  
  309. /*
  310. * flag bits used in calc and calcserv
  311. */
  312. #define CALC_BIT_HELIO 1   /* geo/helio */
  313. #define CALC_BIT_NOAPP 2   /* apparent/true positions */
  314. #define CALC_BIT_NONUT 4   /* true eq. of date/ mean equ. of date */
  315. #define CALC_BIT_EPHE  8   /* universal/ephemeris time */
  316. #define CALC_BIT_SPEED 16  /* without/with speed */
  317. #define CALC_BIT_BETA  32  /* without/with latitude */
  318. #define CALC_BIT_RGEO  64  /* without/with relative rgeo */
  319. #define CALC_BIT_RAU   128 /* without/with real radius */
  320. #define CALC_BIT_MUST_USE_EPHE 256 /* epheserv may not use calc */
  321. #define CALC_BIT_MAY_USE_EPHE  512 /* calcserv may use ephread */
  322.  
  323. #define EPHE_STEP 80              /* days step in LRZ ephe */
  324. #define EPHE_DAYS_PER_FILE 100000 /* days per ephe file */
  325. #define EPHE_OUTER "LRZ5_"        /* file name prefix */
  326. #define EPHE_OUTER_BSIZE  60      /* blocksize */
  327. #define EPHE_CHIRON "CHI_"        /* file name prefix */
  328. #define EPHE_CHIRON_BSIZE 12      /* blocksize */
  329. #define EPHE_ASTER "CPJV_"        /* file name prefix */
  330. #define EPHE_ASTER_BSIZE  48      /* blocksize */
  331.  
  332. /********************************************
  333. About the format of the ephemeris files
  334. ----------------------------------------
  335. We use currently ephemeris files with steps of 80 days.
  336. There are 1250 "records" in each file, so that one file
  337. spans 100000 days. We have three types of ephemeris files:
  338. LRZ5_nn for the outer planets Jupiter ... Pluto,
  339. CHI_nn for Chiron, and CPJV_nn for the four asteroids Ceres ... Vesta.
  340. nn is an expression derived from the first julian daynumber on the
  341. file. Jd 2100'000 to 2199'920 is on file LRZ5_21, CHI_21, and CPJV_21;
  342. for negative Jd we use the filenames LRZ5_Mxx  with M indicating the minus.
  343.  
  344. Given the jd for which you want the ephemeris, it is simple to build
  345. the filename and use fseek() within the file to go where the data is.
  346. This is done by the functions lrz_file_posit() and chi_file_posit().
  347.  
  348. The stored coordinates are for each date and planet:
  349. L = ecliptic longitude relative to mean exquinox of date,
  350. in units of milliseconds of acr (1/3600000 degree) as type long;
  351. R = radius vector, units of 10-7 AU, as type long.
  352. Z = disctance of ecliptic; Z = R * sin(latitude); in units of 10-7 AU,
  353. as type long.
  354. The data is stored in the byte ordering of the Astrodienst HPUX machines,
  355. which is most significant byte first. It is not the same byte ordering
  356. as on Intel processors; the function longreorder() converts between
  357. the disk file format and the internal format of MSDOS machines.
  358.  
  359. For LRZ5- files, we have 60-byte records LRZ(Jupiter),LRZ(Saturn),
  360. LRZ(Uranus), LRZ(Neptune), LRZ(Pluto).
  361. For CHI- files we have 12-byte records LRZ.
  362. For CPJV- files we have 48-byte records.
  363.  
  364. ************************************************/
  365.  
  366.  
  367. /*************************************************************
  368. placalc2.c definitions
  369. *************************************************************/
  370.  
  371. #define SDNUM 20
  372. #define NUM_MOON_CORR 93
  373.  
  374. struct eledata {
  375. REAL8 axis,   /* mean distance, in a.u., A(N) in basic */
  376. period,   /* days for one revolution, P(N) in basic */
  377. epoch,    /* relative juldate of epoch, Ep(N) in basic */
  378. /* T = distance to epoch in jul.centuries 36525 day*/
  379. lg0,lg1,lg2,lg3,/* deg(epoch), degree/day, seconds/T^2,seconds/T^3 */
  380. /* Pd(N,0..2) in basic, lg3 was not present */
  381. pe0,pe1,pe2,pe3,/* deg(epoch), seconds/T,  seconds/T^2,seconds/T^3 */
  382. /* Pd(N,3..5) in basic, pe3 was not present */
  383. ex0,ex1,ex2,  /* ecl(epoch), 1/T, 1/T^2 */
  384. /* Pd(N,6..8) in basic */
  385. kn0,kn1,kn2,kn3,/* node(epoch),seconds/T,  seconds/T^2,seconds/T^3 */
  386. /* Pd(N,9..11) in basic, kn3 was not present */
  387. in0,in1,in2;    /* incl(epoch),1/T, 1/T^2 */
  388. /* Pd(N,12..14) in basic */
  389. };
  390.  
  391. struct kor {
  392.   int     j, i;
  393.   REAL8   lampl;  /* amplitude of disturbation in long, seconds of arc */
  394.   REAL8 lphase;   /* phase of disturbation in long, degrees */
  395.   INT4    rampl;  /* ampl. of disturbation in radius, 9th place of log */
  396.   REAL8   rphase; /* phase of disturbation in radius, degrees */
  397.   int     k;      /* index into disturbing planet anomaly table sa[] */
  398. };
  399.  
  400. struct sdat {   /* 0..19 mean anomalies of disturbing planets
  401.   Sd(0..19,0..1) in basic */
  402.   REAL8 sd0,  /* mean anomaly at epoch 1850 */
  403.   sd1;  /* degrees/year */
  404. };
  405.  
  406. /* moon correction data; revised 30-jul-88: all long. to 0.3" */
  407. struct m45dat {
  408.   int  i0,i1,i2,i3;
  409.   REAL8 lng,lat,par;
  410. };
  411.  
  412. extern struct eledata pd[MARS + 1];
  413. extern struct kor earthkor[86+1];
  414. extern struct kor mercurykor[24+1];
  415. extern struct kor venuskor[22+1];
  416. extern struct kor marskor[62+1];
  417. extern struct sdat _sd [SDNUM];
  418. extern struct m45dat m45[NUM_MOON_CORR];
  419. extern REAL8 ekld[4];
  420. extern REAL8 sa[SDNUM];
  421. extern double degnorm();
  422. extern REAL8 fnu();
  423. extern REAL8 smod8360();
  424. extern REAL8 mod8360();
  425. extern REAL8 diff8360();
  426. extern REAL8 test_near_zero();
  427.  
  428. /*******************************************
  429. $Header: astrolib.h,v 1.2 91/11/16 16:21:02 alois Exp $
  430. astrolib.h
  431.  
  432. *******************************************/
  433.  
  434. /* macros for bit operations */
  435.  
  436. #define clear_bit(v,bit_nr) ((v) & ~(1L << (bit_nr)))
  437. #define set_bit(v,bit_nr)   ((v) | (1L << (bit_nr)))
  438. #define bit(bit_nr)         (1L << (bit_nr))
  439. #define check_bit(v,bit_nr) ((v) & (1L << (bit_nr)))
  440.  
  441. #endif /* PLACALC */
  442.  
  443. /* placalc.h */
  444.